// 云函数入口文件
const cloud = require('wx-server-sdk')

cloud.init()

// 云函数入口函数
exports.main = async (event, context) => {
  const wxContext = cloud.getWXContext()
  const id = event.id
  const formId = event.formId
  const username = event.username
  const createTime = event.createTime
  await cloud.openapi.templateMessage.send({
    touser: wxContext.OPENID,
    page: '/pages/login/index',
    data: {
      keyword1: {
        value: id
      },
      keyword2: {
        value: username
      },
      keyword3: {
        value: '恭喜注册【海螺V】小程序成功'
      },
      keyword4: {
        value: createTime
      },
      keyword5: {
        value: '永久有效'
      },
      keyword6: {
        value: 'tdatgw'
      },
      keyword7: {
        value: '下次进入小程序将自动登录'
      }
    },
    templateId: '5-Gxpwf3OQJFTOziMLUWGs4QyPQo_E2IColAV9Hw-yc',
    formId,
    emphasisKeyword: 'keyword2.DATA'
  })
  return {
    event,
    openid: wxContext.OPENID
  }
}